package com.currency.mall.ui.my.capital;

import com.currency.mall.Constant;
import com.currency.mall.entity.CapitalFlowBean;
import com.currency.mall.netWork.NetWork;
import com.mifengs.commonbase.util.ToastUitl;

import java.util.HashMap;

import rx.Observer;
import rx.android.schedulers.AndroidSchedulers;
import rx.schedulers.Schedulers;

/**
 * Created by Administrator on 2018/12/26.
 */

public class CapitalDetailsPresent implements CapitalDetailsContract.Presenter {
    private CapitalDetailsContract.View mView;

    public CapitalDetailsPresent(CapitalDetailsContract.View mView) {
        this.mView = mView;
    }

    @Override
    public void getCapitalDetailsData(int page, String status) {
        HashMap<String,Object> hashMap = new HashMap<>();
        if(mView.position() != 0){
            hashMap.put("status",status);
        }
        hashMap.put("pageNum",page);
        hashMap.put("pageSize",20);
        NetWork.getUserApi().capitalList(hashMap)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .compose(mView.<CapitalFlowBean>bindToLife())
                .subscribe(new Observer<CapitalFlowBean>() {
                    @Override
                    public void onCompleted() {

                    }

                    @Override
                    public void onError(Throwable e) {
                        mView.finishRefresh();
                    }

                    @Override
                    public void onNext(CapitalFlowBean capitalFlowBean) {
                        mView.finishRefresh();
                        if(capitalFlowBean.getCode().equals(Constant.SUCCESS_CODE)){

                            mView.setData(capitalFlowBean.getAccountLog());

                        }else{
                            ToastUitl.show(capitalFlowBean.getMsg(),200);
                        }

                    }
                });

    }

}
